package ema.tpjee.banking.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;



import org.hibernate.annotations.IndexColumn;

public class Customer implements Serializable {

	private static final long serialVersionUID = 7204194554910037494L;


	private int id;

	private String name;
	private String forName;
	private String address;
	private String zipCode;
	
	private List<Account> accounts;

	public List<Account> getAccounts() {
		return accounts;
	}

	public void setAccounts(List<Account> accounts) {
		this.accounts = accounts;
	}	
	

	private Bank bank;

	private City city;

	public City getCity() {
		return city;
	}

	public void setCity(City city) {
		this.city = city;
	}


	public void addAccount(Account account) {
		account.setOwner(this);
		accounts.add(account);
		if (accounts.size() > 0) {
			System.out.println("accounts for customer " + this);
			for (Account ac : accounts) {
				System.out.println(ac.getId());
			}
		} else
			System.out.println("no accounts for customer " + this);
	}

	public void removeAccount(Account account) {
		this.accounts.remove(account);
		account.setOwner(null);
	}

	public Customer(String name, String forName, String address, String zipCode) {
		this();
		this.name = name;
		this.forName = forName;
		this.address = address;
		this.zipCode = zipCode;

	}

	public Customer(String name) {
		this();
		this.name = name;
	}

	public Customer() {
		super();
		accounts = new ArrayList<Account>();
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getForName() {
		return forName;
	}

	public void setForName(String forName) {
		this.forName = forName;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getZipCode() {
		return zipCode;
	}

	public void setZipCode(String zipCode) {
		this.zipCode = zipCode;
	}

	public String toString() {
		String result = id + " " + forName + " " + name;
		if (getCity() != null)
			result += ";" + getCity().toString();
		else
			result += ";city=null";
		return result;
	}

	public void setBank(Bank b) {
		this.bank = b;
	}

	public Bank getBank() {
		return bank;
	}

	@Override
	public boolean equals(Object other) {
		if (!(other instanceof Customer))
			return false;
		return this.id == ((Customer) other).id;
	}

	@Override
	public int hashCode() {
		return new Integer(id).hashCode();
	}

}
